<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>工资管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="__TMPL__/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="__TMPL__/css/admin.css" media="all">
	<script type="text/javascript" src="__TMPL__/js/jquery.min.js"></script>
	<script type="text/javascript" src="__TMPL__/layui/layui.js"></script>
	<script type="text/javascript" src="__TMPL__/js/admin.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/admin.js"></script>
    <script type="text/javascript" src="__TMPL__/layui/lay/modules/util.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="date" name="date" placeholder="请选择日期">
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <select name="role">
                            <option value="0">管理员</option>
                            <option value="1">超级管理员</option>
                            <option value="2">纠错员</option>
                            <option value="3">采购员</option>
                            <option value="4">推销员</option>
                            <option value="5">运营人员</option>
                            <option value="6">编辑</option>
                        </select><div class="layui-unselect layui-form-select"><div class="layui-select-title"><input type="text" placeholder="请选择" value="管理员" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit"><dd lay-value="0" class="layui-this">管理员</dd><dd lay-value="1" class="">超级管理员</dd><dd lay-value="2" class="">纠错员</dd><dd lay-value="3" class="">采购员</dd><dd lay-value="4" class="">推销员</dd><dd lay-value="5" class="">运营人员</dd><dd lay-value="6" class="">编辑</dd></dl></div>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit="" lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <eq name="cycle_count" value="0">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="create">一键生成</button>
                    </eq>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
            <script type="text/html" id="switchTpl">
                <input type="checkbox" name="is_full" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="full" {{ d.is_full == 1 ? 'checked' : '' }}>
                 |  <span style="font-size: 16px;color: #009688">{{d.full_attendance}}</span>
            </script>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="release">批量发放</button>
                    <button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="calculation">计算工资</button>
                </div>
            </script>
            <script type="text/html" id="status">
                {{# if(d.status == 0){ }}
                <span style="color: red">待完善</span>
                {{# }else if(d.status == 1){ }}
                <span style="color: red">部分发放</span>
                {{# }else if(d.status == 2){ }}
                已发完
                {{# }else if(d.status == 3){ }}
                未发放
                {{# } }}
            </script>
            <script type="text/html" id="login_time">
                {{ time2date(d.last_login_time) }}
            </script>
            <script type="text/html" id="options">
                <div class="layui-btn-group">
                    <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" lay-event="release">
                        <i class="layui-icon layui-icon-rmb layuiadmin-button-btn"></i>发放
                    </button>
                </div>
            </script>
        </div>
    </div>
</div>
<script type="text/html" id="check">
    <input type="radio" name="layTableCheckbox" value="{{d.id}}" lay-filter="check">
</script>
<script>
    layui.config({
        base: '__TMPL__/public/', //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['layer', 'table', 'form','laydate','index','admin'], function () {
        var table       = layui.table,
            layer       = layui.layer,
            laydate     = layui.laydate,
            form        = layui.form,
            admin       = layui.admin;
        //监听搜索
        form.on('submit(search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('dataTable', {
                where: field
            });
        });
        form.on('submit(create)', function(data){
            admin.req({
                url: "{:url('wage/wage_create')}",
                method:'post',
                type:'json',
                done:function (res) {
                    if(res.code===1){
                        layer.msg(res.msg, function(){
                            table.reload('dataTable');
                        });
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        });

        laydate.render({
            elem: '#date'
            ,type: 'month'
        });

        var $ = layui.$, active = {
            batchdel: function(){
                var checkStatus = table.checkStatus('dataTable')
                    ,checkData = checkStatus.data; //得到选中的数据

                if(checkData.length === 0){
                    return layer.msg('请选择数据');
                }

                layer.confirm('确定删除吗？', function(index) {

                    //执行 Ajax 后重载
                    /*
                    admin.req({
                      url: 'xxx'
                      //,……
                    });
                    */
                    table.reload('dataTable');
                    layer.msg('已删除');
                });
            },
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加文章'
                    ,content: 'listform.html'
                    ,maxmin: true
                    ,area: ['550px', '550px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //用户表格初始化
        var dataTable = table.render({
            elem: '#dataTable'
            ,url: "{:url('wage/wage_data')}"
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,page: true
            ,response: {
                statusCode: 1
            }
            ,limit:50
            ,limits:[50,100]
            ,totalRow: true
            , cols: [[ //表头
                  {checkbox: true, fixed: true, unresize: true, sort: true,totalRowText: '总计'}
                , {field: 'name', title: "姓名"}
                , {field: 'wages_basic', title: "基本工资", totalRow: true}
                , {field: 'bonus', title: "奖金",edit: 'text', totalRow: true}
                , {field: 'is_full', title: "全勤", templet: '#switchTpl', width:150,unresize: true}
                , {field: 'deduction', title: "扣除",edit: 'text'}
                , {field: 'wage', title: "本月工资", sort: true,totalRow: true}
                , {field: 'wages_paid', title: "已发", totalRow: true}
                , {field: 'remark', title: "备注",edit: 'text'}
                , {field: 'status', title: "{:lang('STATUS')}", toolbar: '#status'}
                , {fixed: 'right', title: '操作', align: 'left', toolbar: '#options'}
            ]]
        });
        form.on('switch(full)', function(obj){
            var data = {is_full:0};
            data.wage_id = this.value
            if(obj.elem.checked===true){
                data.is_full = 1;
            }
            admin.req({
                url: "{:url('wage/set_full')}",
                method:'post',
                type:'json',
                data:data,
                done:function (res) {
                    if(res.code===1){
                        layer.msg(res.msg, {
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            table.reload('dataTable');
                        });

                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        });
        table.on('edit(dataTable)', function(obj){
            admin.req({
                url: "{:url('wage/set_value')}",
                method:'post',
                type:'json',
                data:obj.data,
                done:function (res) {
                    if(res.code===1){
                        layer.msg(res.msg, function(){
                            table.reload('dataTable');
                        });
                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        });

        table.on('toolbar(dataTable)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'release':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));

                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'release') {
                layer.open({
                    type: 2
                    ,title: '工资发放'
                    ,content: "/admin/wage/pay?wage_id="+data.id+"&name="+data.name+"&wage="+data.wage+"&wages_paid="+data.wages_paid
                    ,maxmin: true
                    ,area: ['300px', '270px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }else if (obj.event === 'delete') {
                var del = layer.confirm('确定要删除吗？', {
                    btn: ['删除', '暂不'] //按钮
                }, function () {
                    /*
                    执行删除
                    */
            });
        }
    });
});
function time2date(t) {
var t1 = parseInt(t + '000');
return layui.util.toDateString(t1);
}
</script>
</body>
</html>